/**
 * Predefined variables
 * Name = CommodityItem
 * DateTime = Tue Jan 18 2022 21:53:25 GMT+0800 (中国标准时间)
 * Author = Created by zhj9922
 * FileBasename = CommodityItem.ts
 * gitee： https://gitee.com/coyeking
 */
 
import { _decorator, Component,Sprite,Label } from 'cc';
import { audioManager } from '../../../framework/audioManager';
import { resourceUtil } from '../../../framework/resourceUtil';
const { ccclass, property } = _decorator;
import { notifyEvent } from '../../../framework/notifyEvent';
import { constant } from '../../../define/constant';
 
@ccclass('CommodityItem')
export class CommodityItem extends Component {
    @property(Sprite)
    public ui_bg: Sprite = null;
    
    @property(Label)
    public ui_title: Label = null;
    
    @property(Label)
    public ui_price: Label = null;
	
    public index:number = 0;

    init (item) {
        this.index = item.id;

        this.ui_title.string = `${item.gold}钻石`
        this.ui_price.string = `￥${item.price}元`
        let price = Number(item.price);

        let imgurl = 'zuanshi_dian30';
        if (price >= 6 && price < 20){
            imgurl = 'zuanshi_dian50';
        }else if (price >= 20 && price < 50){
            imgurl = 'zuanshi_dian180';
        }else if (price >= 50 && price < 100){
            imgurl = 'zuanshi_dian500';
        }else if (price >= 100 && price < 150){
            imgurl = 'zuanshi_dian1030';
        }else if (price >= 150 && price < 240){
            imgurl = 'zuanshi_dian2100';
        }else if (price >= 240 && price < 400){
            imgurl = 'zuanshi_dian5380';
        }else if (price >= 500){
            imgurl = 'zuanshi_dian8888';
        }

        let url = `texture/hall/shop/${imgurl}`;
        resourceUtil.loadSpriteFrameRes(url,this.ui_bg);
    };
	
    /**
     * 按钮点击事件
     * @param event 
     * @param customEventData 
     */
	private onClick (event: Event, customEventData: string) {
        audioManager.instance.playSound();

        notifyEvent.dispatchEvent(constant.NOTIFY_EVENT.notify_shopindex,this.index);
    }
}

